package com.era.srv.impl;

import java.util.List;

import com.era.dao.UsersDAO;
import com.era.entity.Users;
import com.era.srv.UsersSrv;

public class UsersSrvImpl implements UsersSrv{
	
	private UsersDAO usersDAO;
	
	
	public boolean validateLogin(String usersName,String usersPasswd) {
		/*return usersDAO.findByUsersName(usr.getUsersName()).size() > 0
				&& usersDAO.findByUsersPasswd(usr.getUsersPasswd()).size() > 0;*/
		return usersDAO.validateLogin(usersName,usersPasswd);
	}

	public boolean registerUser(Users usr) {
		// TODO Auto-generated method stub
		boolean flag = false;
		try{
			usersDAO.save(usr);
			flag = true;
		}catch(RuntimeException re){
			re.printStackTrace();
		}
		return flag;
	}

	public boolean deleteUser(Users usr) {
		// TODO Auto-generated method stub
		boolean flag = false;
		try{
			usersDAO.delete(usr);
			flag = true;
		}catch(RuntimeException re){
			re.printStackTrace();
		}
		return flag;
	}

	public Users findById(Integer id) {
		// TODO Auto-generated method stub
		return usersDAO.findById(id);
	}
	
	public Users merge(Users detachedInstance) {
		// TODO Auto-generated method stub
		return usersDAO.merge(detachedInstance);
	}

	public List findAll() {
		// TODO Auto-generated method stub
		return usersDAO.findAll();
	}
	
	public List findByQuery(String name) {
		return usersDAO.findByQuery(name);
	}

	public UsersDAO getUsersDAO() {
		return usersDAO;
	}

	public void setUsersDAO(UsersDAO usersDAO) {
		this.usersDAO = usersDAO;
	}
	
	
}
